package com.gitee.zycra.union.api.web.controller;

import com.gitee.zycra.union.api.common.bo.CommonResult;
import com.gitee.zycra.union.api.service.ApiProjectGroupService;
import com.gitee.zycra.union.api.web.annotation.AuthCheck;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zycra
 */
@RestController
@RequestMapping("/projectGroup")
public class ApiProjectGroupController {

    @Autowired
    private ApiProjectGroupService apiProjectGroupService;

    /**
     * 添加项目组
     *
     * @param groupName 项目组名称
     * @return 添加结果
     */
    @AuthCheck({"0"})
    @PostMapping("/addGroup")
    public CommonResult<String> addGroup(@RequestParam("groupName") String groupName) {
        return apiProjectGroupService.addGroup(groupName);
    }

    /**
     * 根据ID更新项目组
     *
     * @param id        项目组ID
     * @param groupName 项目组名称
     * @return 更新条数
     */
    @AuthCheck({"0"})
    @PostMapping("/updateGroup")
    public CommonResult<String> updateGroup(@RequestParam("id") Long id, @RequestParam("groupName") String groupName) {
        apiProjectGroupService.updateGroup(id, groupName);
        return CommonResult.success();
    }

    /**
     * 根据ID删除项目组
     *
     * @param id 项目组ID
     * @return 删除条数
     */
    @AuthCheck({"0"})
    @PostMapping("/deleteGroup")
    public CommonResult<String> deleteGroup(@RequestParam("id") Long id) {
        apiProjectGroupService.deleteGroup(id);
        return CommonResult.success();
    }
}
